package cn.maszy.action.investment;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;

import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.model.investment.B_T_Ufp_Staffinformation;
import cn.maszy.service.investment.B_T_Ufp_StaffinformationService;



public class StaffInformationAction extends  BaseAction<B_T_Ufp_Staffinformation>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private  B_T_Ufp_StaffinformationService b_T_Ufp_StaffinformationService;
	private B_T_Ufp_Staffinformation b_T_Ufp_Staffinformation;
	private String checkIds;
	//状态判断
	private String status;
	//修改判断
	private String flag;
	/*********************class set/get****************************/
	public B_T_Ufp_Staffinformation getB_T_Ufp_Staffinformation() {
		return b_T_Ufp_Staffinformation;
	}
	public void setB_T_Ufp_Staffinformation(
			B_T_Ufp_Staffinformation b_T_Ufp_Staffinformation) {
		this.b_T_Ufp_Staffinformation = b_T_Ufp_Staffinformation;
	}
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 插入
	 */
	public String staffInformationUpdate()
	{
		int i=b_T_Ufp_StaffinformationService.update(b_T_Ufp_Staffinformation,flag);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "StaffInformationList","", "forward", "investment/StaffInformationList?b_T_Ufp_Staffinformation.status=在职");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	public String ziliaoUpdate() throws Exception {
		int i=b_T_Ufp_StaffinformationService.update(b_T_Ufp_Staffinformation,"");
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "","", "forward", "");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	public  String staffCallback() 
	{
		pager = new Pager<B_T_Ufp_Staffinformation>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_StaffinformationService.selectList(b_T_Ufp_Staffinformation,pager);
		return SUCCESS;
	}
	/**
	 * 查询
	 * @return
	 */
	
	public  String staffInformationList() 
	{
		pager = new Pager<B_T_Ufp_Staffinformation>(pageNum, numPerPage,orderField,orderDirection);
		if(status == null || "".equals(status)){
		if(b_T_Ufp_Staffinformation.getStatus() != null || !"".equals(b_T_Ufp_Staffinformation.getStatus())){
			try {
				b_T_Ufp_Staffinformation.setStatus(new String(b_T_Ufp_Staffinformation.getStatus().getBytes("ISO8859_1"),"utf-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		}
		pager= b_T_Ufp_StaffinformationService.selectList(b_T_Ufp_Staffinformation,pager);
		return SUCCESS;
	}
	/**
	 * 删除
	 * @return
	 */
	public String staffInformationDelete()
	{
		System.out.print(checkIds);
		int i=b_T_Ufp_StaffinformationService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "StaffInformationList","", "forward", "investment/StaffInformationList?b_T_Ufp_Staffinformation.status=在职");
		return ajaxForwardError(getText("msg.operation.failure"));
	
	}
	//跳转到新建页面
	public String staffInformationDetail()
	{
		if(b_T_Ufp_Staffinformation==null){
			b_T_Ufp_Staffinformation=b_T_Ufp_StaffinformationService.selectOne("");
		}else{
			b_T_Ufp_Staffinformation=b_T_Ufp_StaffinformationService.selectOne(b_T_Ufp_Staffinformation.getStaffId());
		}
		return SUCCESS;	
	}
	public String staffInDetail(){
		b_T_Ufp_Staffinformation = b_T_Ufp_StaffinformationService.selectOne(SessionFactory.getSessionEmployeeId());
		if(b_T_Ufp_Staffinformation==null){
		b_T_Ufp_Staffinformation=b_T_Ufp_StaffinformationService.selectOne("");
		b_T_Ufp_Staffinformation.setDepname(SessionFactory.getSessionUserDepNam());
		b_T_Ufp_Staffinformation.setStaffName(SessionFactory.getSessionUserRealNam());
	}else{
		b_T_Ufp_Staffinformation=b_T_Ufp_StaffinformationService.selectOne(b_T_Ufp_Staffinformation.getStaffId());
	}
		return SUCCESS;	
	}
}
